var form;
var table;
var layer;
var $;
var upload;
layui.use(['layer','form','table','upload'],function(){
    form = layui.form;
    table=layui.table;
    layer=layui.layer;
    $=layui.$;
    upload=layui.upload;

    //商品订单列表
    showtables();

})

//页面搜索
var seek=function(){
    var orderNo=$('input[name=orderNo]').val();
    var nickname=$('input[name=nickname]').val();
    var productName=$('input[name=productName]').val();

    $.post("/SyOperationController/returnGoods", {"orderStatus":7,"orderNo":orderNo,"nickname":nickname,"productName":productName},
        function (data) {
            tables(data.data);


        });
}
//重置按钮
$("#resetBtn").on("click",function(){
    showtables();
})

//高级检索
function retrieve(){
    var paymentTime=$('input[name=paymentTimes]').val();
    var nicknames=$('input[name=nicknames]').val();
    var orderNo=$('input[name=orderNos]').val();
    var opc=$('input[name=orderPaymentChannels]').val();
    var orderSource=$('input[name=orderSources]').val();
    var productName=$('input[name=productNames]').val();

    $.post("/SyOperationController/returnGoods",
        {"orderStatus":7,"orderNo":orderNo,"nickname":nicknames,"orderPaymentChannel":opc,"paymentTime":paymentTime,"orderSource":orderSource,"productName":productName},
        function (data) {
            tables(data.data);
        });
}
//高级检索弹出层
var search=function(){
    layer.open({
        type:2,  //弹出层类型
        title:"高级检索",
        area:['580px','490px'], //弹出层大小
        shade:0.4, //设置遮罩透明度
        offset:'auto', //设置遮罩位置
        content:'ProductOrderList_search.html', //弹出层内容页面
        success: function (data) {}
    })
    window.layer_1=layer;
}

//展示table表格
function showtables(){
    $.post("/SyOperationController/returnGoods",{"orderStatus":7}, function (data) {
        tables(data.data);
    });
}
//table表格信息
function tables(data){
    table.render({
        elem:"#table_id",//容器
        data:data,
        title:"商品订单列表",
        limit:10,//分页显示条数
        toolbar:"#toolbar_id",
        page:true,
        cols:[[//定义列
            {type:'checkbox',align:'center',width:40},//复选框靠左
            {title:'序号',align:'center',width:60,templet:function(data){
                    return data.LAY_INDEX;
                }},
            {field:"order_no",title:"订单编号",align:'center',width:195},
            {field:"nickname",title:"用户昵称",align:'center'},
            {field:"product_name",title:"商品名称",align:'center'},
            {field:"logistics_fee",title:"订单金额",align:'center',templet:function(data){
                    return  " ￥"+data.logistics_fee;
                }},
            {field:"order_payment_channel",title:"支付方式",align:'center',templet:function(data){
                    if(data.order_payment_channel==2){
                        return  "微信支付 ";
                    }else if(data.order_payment_channel==3){
                        return  " 余额支付";
                    }else if(data.order_payment_channel==4){
                        return  " 未支付";
                    }else if(data.order_payment_channel==5){
                        return  " 支付宝支付";
                    }
                }},
            {field:"order_source",title:"订单来源",align:'center',templet:function(data){
                    if(data.order_source==2){
                        return  "小程序 ";
                    }else if(data.order_source==3){
                        return  " app";
                    }
                }},
            {field:"order_status",title:"订单状态",align:'center',templet:function(data){
                    if(data.order_status==2){
                        return  "待付款";
                    }else if(data.order_status==3){
                        return  "待发货";
                    }else if(data.order_status==4){
                        return  "待发货";
                    }else if(data.order_status==5){
                        return  "已发货";
                    }else if(data.order_status==6){
                        return  "已签收";
                    }else if(data.order_status==7){
                        return  "申请退货";
                    }else if(data.order_status==8){
                        return  "退货中";
                    }else if(data.order_status==9){
                        return  "已退货";
                    }else if(data.order_status==10){
                        return  "取消交易";
                    }else if(data.order_status==11){
                        return  "拒绝退货";
                    }
                }},
            {field:"payment_time",title:"提交时间",align:'center',width:160,templet:function(d){
                    var date=d.payment_time;
                    date = date.slice(0, date.indexOf("."));
                    date = date.replaceAll('T',' ');
                    return date;
                }},
            {field:"",title:"操作",align:'center',width:120,templet:function(data){
                    if(data.order_status==7) {
                        return  "<a style='color:#1ABC9C;cursor:pointer;' onclick='javascript:check(\""+data.order_id+"\");'>查看 </a>  "+
                            "<a style='color:#1ABC9C;cursor:pointer;' onclick='javascript:edit(\""+data.order_id+"\",\""+data.product_name+"\",\""+data.order_type+"\",\""+data.product_id+"\");'> 审核</a>   ";
                    }else{
                        return  "<a style='color:#1ABC9C;cursor:pointer;' onclick='javascript:check(\""+data.order_id+"\");'>查看 </a>";
                    }
                }}
        ]]
    });
}

//查看商品订单详情
var check=function(orderId){
    localStorage.setItem("orderId",orderId); //订单ID
    window.location.href='ProductOrderList_check.html';
}

//审核退货商品信息
var edit=function(orderId,name,orderType,productId){
    audits(orderId,name,orderType,productId);
}

//审核商品信息弹出层
var audits=function(orderId,name,orderType,productId){
    layer.open({
        type:2,  //弹出层类型
        title:"商品审核",
        area:['450px','380px'], //弹出层大小
        shade:0.4, //设置遮罩透明度
        offset:'auto', //设置遮罩位置
        content:'ProductReturnList_audit.html', //弹出层内容页面
        success:function(layero,index){
            //查找当前引入的iframe内容
            var obj=layero.find("iframe").contents();
            //用选择器查找  选中input框
            obj.find('input[name=orderId]').val(orderId);
            obj.find('input[name=productName]').val(name);
            obj.find('input[name=orderType]').val(orderType);
            obj.find('input[name=productId]').val(productId);

        },
    });
    window.layer_1=layer;
}

//刷新按钮
$("#refreshs").on('click',function(){
    window.location.reload();
});